using System;
using Server;
using Server.Spells;
using Server.Mobiles;
using Server.Targets;
using Server.Network;
using AMA = Server.Items.ArmorMeditationAllowance;
using AMT = Server.Items.ArmorMaterialType;
using ABT = Server.Items.ArmorBodyType;

namespace Server.Items
{
	[FlipableAttribute(0x1B7B, 0x1B7B)]
    public class ScudoRotondo : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo Rotondo"; } }
        public override double DefPeso { get { return 8; } }
        public override int DefDifesaBase { get { return 15; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
		
		[Constructable]
        public ScudoRotondo()
            : base(0x1B7B)
        {
        }

        public ScudoRotondo(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1B73, 0x1B73)]
    public class ScudoPiccolo : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo Piccolo"; } }
        public override double DefPeso { get { return 4; } }
        public override int DefDifesaBase { get { return 8; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
		
		[Constructable]
        public ScudoPiccolo()
            : base(0x1B73)
        {
        }

        public ScudoPiccolo(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1BC4, 0x1BC4)]
    public class ScudoDellOrdine : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo dell'Ordine"; } }
        public override double DefPeso { get { return 10; } }
        public override int DefDifesaBase { get { return 20; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
		
		[Constructable]
        public ScudoDellOrdine()
            : base(0x1BC4)
        {
        }

        public ScudoDellOrdine(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	
	[FlipableAttribute(0x1BC3, 0x1BC3)]
    public class ScudoDelCaos : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo del Caos"; } }
        public override double DefPeso { get { return 10; } }
        public override int DefDifesaBase { get { return 20; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
		
		[Constructable]
        public ScudoDelCaos()
            : base(0x1BC3)
        {
        }

        public ScudoDelCaos(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x2B01, 0x2B01)]
    public class ScudoTattico : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo Tattico"; } }
        public override double DefPeso { get { return 15; } }
        public override int DefDifesaBase { get { return 28; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
		
		[Constructable]
        public ScudoTattico()
            : base(0x2B01)
        {
        }

        public ScudoTattico(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1B76, 0x1B76)]
    public class ScudoTorre : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo a Torre"; } }
        public override double DefPeso { get { return 19; } }
        public override int DefDifesaBase { get { return 30; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }

        protected static DefaultSkillMod m_BonusParareOnMount;
        protected static DefaultSkillMod m_BonusResSpellOnMount;
        protected static StatMod m_BonusDifesaOnMount;
        protected static DefaultSkillMod m_BonusParareAPiedi;
        protected static DefaultSkillMod m_BonusResSpellAPiedi;
        protected static StatMod m_BonusDifesaOnAPiedi;

        private enum TipoImpugnatura
        {
            Nessuna,
            APiedi,
            Mounted
        }

        private TipoImpugnatura Impugnatura;

        public static void Initialize()
        {
            m_BonusParareOnMount = new DefaultSkillMod(SkillName.Parry, true, 6.0);
            m_BonusResSpellOnMount = new DefaultSkillMod(SkillName.MagicResist, true, 6.0);
            m_BonusDifesaOnMount = new StatMod(StatType.Difesa, "ScudoTorre_Difesa_OnMount", 4, TimeSpan.Zero);
            m_BonusParareAPiedi = new DefaultSkillMod(SkillName.Parry, true, 12.0);
            m_BonusResSpellAPiedi = new DefaultSkillMod(SkillName.MagicResist, true, 12.0);
            m_BonusDifesaOnAPiedi = new StatMod(StatType.Difesa, "ScudoTorre_Difesa_APiedi", 6, TimeSpan.Zero);
        }

		[Constructable]
        public ScudoTorre()
            : base(0x1B76)
        {
            Impugnatura = TipoImpugnatura.Nessuna;
        }

        public ScudoTorre(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }

        public override bool OnEquip(Mobile from)
        {
            if (!base.OnEquip(from))
                return false;

            if (from is PlayerMobile)
            {
                PlayerMobile player = (PlayerMobile)from;

                // MDA con presa possente (potere livello 34) puo' indossare lo scudo a torre a cavallo.
                if (player.Mounted && (player.Classe != NomeClasse.MaestroDArme || player.Livello < 34))
                {
                    player.SendMessage("Non puoi impugnare uno scudo a torre mentre cavalchi");
                    return false;
                }
                else if (player.Mounted)
                {
                    player.PublicOverheadMessage(MessageType.Emote, 0x240, false, "*Impugni lo scudo con una presa possente*");
                }
            }
            // Il Mobile e' su una cavalcatura
            if (from.Mount != null)
            {
                AddBonusMounted(from);
            }
            // Il Mobile e' a piedi
            else
            {
                AddBonusAPiedi(from);
            }

            return true;
        }

        public override void OnRemoved(object parent)
        {
            if (parent is Mobile)
            {
                RimuoviBonus((Mobile)parent);
            }

            Impugnatura = TipoImpugnatura.Nessuna;
        }

        public void AddBonusMounted(Mobile m)
        {
            if (Impugnatura == TipoImpugnatura.Mounted)
                return;

            Impugnatura = TipoImpugnatura.Mounted;

            RimuoviBonus(m);

            m.AddSkillMod(m_BonusParareOnMount);
            m.AddSkillMod(m_BonusResSpellOnMount);
            m.AddStatMod(m_BonusDifesaOnMount);
        }

        public void AddBonusAPiedi(Mobile m)
        {
            if (Impugnatura == TipoImpugnatura.APiedi)
                return;

            Impugnatura = TipoImpugnatura.APiedi;

            RimuoviBonus(m);

            m.AddSkillMod(m_BonusParareAPiedi);
            m.AddSkillMod(m_BonusResSpellAPiedi);
            m.AddStatMod(m_BonusDifesaOnAPiedi);
        }

        public void RimuoviBonus(Mobile from)
        {
            // Rimuoviamo tutto a prescindere.
            from.RemoveSkillMod(m_BonusParareOnMount);
            from.RemoveSkillMod(m_BonusResSpellOnMount);
            from.RemoveSkillMod(m_BonusParareAPiedi);
            from.RemoveSkillMod(m_BonusResSpellAPiedi);
            from.RemoveStatMod("ScudoTorre_Difesa_OnMount");
            from.RemoveStatMod("ScudoTorre_Difesa_APiedi");
        }
    }
	
	[FlipableAttribute(0x1B74, 0x1B74)]
    public class ScudoCavaliere : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo da Cavaliere"; } }
        public override double DefPeso { get { return 10; } }
        public override int DefDifesaBase { get { return 22; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
	
		[Constructable]
        public ScudoCavaliere()
            : base(0x1B74)
        {
        }

        public ScudoCavaliere(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1B72, 0x1B72)]
    public class ScudoMetallico : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo Metallico"; } }
        public override double DefPeso { get { return 14; } }
        public override int DefDifesaBase { get { return 26; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
	
		[Constructable]
        public ScudoMetallico()
            : base(0x1B72)
        {
        }

        public ScudoMetallico(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1B7A, 0x1B7A)]
    public class ScudoLegno : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo di Legno"; } }
        public override double DefPeso { get { return 3; } }
        public override int DefDifesaBase { get { return 18; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
	
		[Constructable]
        public ScudoLegno()
            : base(0x1B7A)
        {
        }

        public ScudoLegno(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
	
	[FlipableAttribute(0x1B79, 0x1B79)]
    public class ScudoLegnoRifinito : ArmaturaBase
    {
        public override String DefNome { get { return "Scudo di Legno Rifinito"; } }
        public override double DefPeso { get { return 8; } }
        public override int DefDifesaBase { get { return 22; } }
        public override AMT DefTipoDiMateriale { get { return AMT.Piastre; } }
        public override Layer DefLayer { get { return Layer.TwoHanded; } }
	
		[Constructable]
        public ScudoLegnoRifinito()
            : base(0x1B79)
        {
        }

        public ScudoLegnoRifinito(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
}
